package com.gy.paidao.main.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gy.paidao.R;
import com.gy.paidao.main.bean.CommentBean;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.awt.font.TextAttribute;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 作者：gy on 16/4/14
 * 说明：泡泡详情评论列表
 */
public class BabblesDetailAdapter extends BaseAdapter {

    private Context context;
    private List<CommentBean> list;

    public BabblesDetailAdapter(Context context,List<CommentBean> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.adapter_babbles_comment,null);
            holder = new ViewHolder();
            holder.imgHead = (ImageView) convertView.findViewById(R.id.adapter_babble_detail_img_head);
            holder.tvName = (TextView) convertView.findViewById(R.id.adapter_babble_detail_tv_name);
            holder.tvTime = (TextView) convertView.findViewById(R.id.adapter_babble_detail_tv_time);
            holder.tvContent = (TextView) convertView.findViewById(R.id.adapter_babble_detail_tv_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvContent.setText(list.get(position).content+"");
        holder.tvName.setText(list.get(position).criticName+"");


        if(!TextUtils.isEmpty(list.get(position).criticHeadPortrait)){
            ImageLoader.getInstance().displayImage(list.get(position).criticHeadPortrait,holder.imgHead);
        }

        String time = list.get(position).createTime;
//        time = "2016-04-24 15:53:03";
        if(!TextUtils.isEmpty(list.get(position).createTime)){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat format1 = new SimpleDateFormat("MM-dd HH:mm");
            SimpleDateFormat format2 = new SimpleDateFormat("HH:mm");
            SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd");
            //95752
            try {
                String timeDay = format3.format(format.parse(time));
                String timeToday = format3.format(new Date());
                if(timeDay.equals(timeToday)){
                    time = format2.format(format.parse(time));
                } else {
                    time = format1.format(format.parse(time));
                }
                holder.tvTime.setText(time);
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }

        return convertView;
    }


    class ViewHolder{
        ImageView imgHead;
        TextView tvName,tvTime,tvContent;
    }
}
